package com.atguigu.spring6.resource;

import org.springframework.core.io.UrlResource;

import java.io.IOException;
import java.net.MalformedURLException;

//演示UrlResource访问网络资源
public class UrlResourceDemo {
    public static void main(String[] args) {
        //http前缀的资源
        //loadUrlResource("http://www.baidu.com");
        //file前缀
        loadUrlResource("file:atguigu.txt");
    }
    //访问前缀http、file
    public static void loadUrlResource(String path)   {
        //创建Resource实现类的对象
        UrlResource resource = null;
        try {
            resource = new UrlResource(path);
            //获取资源信息
            System.out.println(resource.getFilename());
            System.out.println(resource.getURL());
            System.out.println(resource.getDescription());
            System.out.println(resource.getInputStream().read());
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
